home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SCRIPT.PAK / DIRVIEW.SPP < prev    next >
Text File  |  1997-05-06  |  6KB  |  209 lines

  1. //----------------------------------------------------------------------------
  2. // cScript
  3. // (C) Copyright 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. // DIRVIEW.SPP
  6. //    Script component of IDE's directory navigator.
  7. //
  8. // $Revision:   1.2  $
  9. //
  10. //----------------------------------------------------------------------------
  11. import IDE;
  12.  
  13. declare acOriginalDirectory;
  14.  
  15. class DirectoryListWindow(nTop, nLeft, nHeight, nWidth, acCaption, bMultipleSelect, bSorted, asIntialValues)
  16. : ListWindow(nTop, nLeft, nHeight, nWidth, acCaption, bMultipleSelect, bSorted, asIntialValues)
  17. {
  18.  declare acCurrentDirectory = "C:\\";
  19.  
  20.  FillDirectoryList()
  21.  {
  22.   Clear();
  23.   Hidden = true;
  24.  
  25.   declare nIndex = 0;
  26.   declare nListCount = 0;
  27.   declare array aacTempList[300];
  28.  
  29.   acOriginalDirectory = GetCurrentDirectory();
  30.   SetCurrentDirectory(acCurrentDirectory);
  31.  
  32.   if ((aacTempList[nIndex++] = IDE.FindFirstFile("*.*")) != "")
  33.      {
  34.       nListCount++;
  35.       while ((aacTempList[nIndex++] = IDE.FindNextFile()) != "")
  36.          nListCount++;
  37.      }
  38.  
  39.   for (nIndex = 0; nIndex < nListCount; nIndex++)
  40.      {
  41.       SetCurrentDirectory(aacTempList[nIndex]);
  42.  
  43.       if (GetCurrentDirectory() == acCurrentDirectory + aacTempList[nIndex])
  44.           Add("+ " + aacTempList[nIndex]);
  45.       else
  46.           Add("  " + aacTempList[nIndex]);
  47.  
  48.       SetCurrentDirectory(acCurrentDirectory);
  49.      }
  50.  
  51.   Caption = acCurrentDirectory;
  52.   Hidden = false;
  53.   SetCurrentDirectory(acOriginalDirectory);
  54.  }
  55.  
  56.   FillDrivesList()
  57.   {
  58.    Clear();
  59.    Hidden = true;
  60.  
  61.    declare nIndex = 0;
  62.    declare nListCount = 0;
  63.  
  64.    declare acOriginalDirectory = GetCurrentDirectory();
  65.  
  66.    declare sDrive = new String;
  67.  
  68.    Add("A:\\", 0);
  69.    Add("B:\\", 1);
  70.  
  71.    nListCount = 2;
  72.  
  73.    acOriginalDirectory = GetCurrentDirectory();
  74.  
  75.    for (nIndex = 67; nIndex < 91; nIndex++)
  76.      {
  77.       sDrive.Character = nIndex;
  78.       SetCurrentDirectory(sDrive.Text + ":\\");
  79.  
  80.       if (GetCurrentDirectory() == sDrive.Text + ":\\")
  81.          {
  82.           Add(sDrive.Text + ":\\", nListCount++);
  83.          }
  84.      }
  85.  
  86.    Caption = "Directory Navigator";
  87.    Hidden = false;
  88.    SetCurrentDirectory(acOriginalDirectory);
  89.   }
  90. };
  91.  
  92. declare dlwList = DirectoryListWindow(0,0,500,200,"",false,true);
  93. dlwList.Execute();
  94. dlwList.FillDrivesList();
  95.  
  96. on dlwList:>Accept()
  97. {
  98.  if (dlwList.CurrentIndex != -1)
  99.    {
  100.     declare acNewDirectory = "";
  101.     declare sNewDirectory = new String(dlwList.GetString(dlwList.CurrentIndex));
  102.  
  103.       if (sNewDirectory.SubString(1,2).Text == ":\\")
  104.        {
  105.         dlwList.acCurrentDirectory = sNewDirectory.Text;
  106.         dlwList.FillDirectoryList();
  107.        }
  108.     else if (sNewDirectory.Text == "  ..")
  109.        {
  110.         dlwList.PreviousDir();
  111.        }
  112.     else if (sNewDirectory.SubString(0,2).Text == "+ ")
  113.        {
  114.         acNewDirectory = sNewDirectory.SubString(2).Text;
  115.         acNewDirectory = dlwList.acCurrentDirectory + acNewDirectory ;
  116.         acOriginalDirectory = GetCurrentDirectory();
  117.         SetCurrentDirectory(acNewDirectory);
  118.  
  119.         if (GetCurrentDirectory() == acNewDirectory)
  120.            {
  121.             dlwList.acCurrentDirectory = acNewDirectory + "\\";
  122.             dlwList.FillDirectoryList();
  123.            }
  124.         SetCurrentDirectory(acOriginalDirectory);
  125.        }
  126.     else if (sNewDirectory.SubString(0,2).Text == "  ")
  127.        {
  128.         IDE.DoFileOpen(dlwList.acCurrentDirectory+sNewDirectory.SubString(2).Text);
  129.        }
  130.   }
  131. }
  132.  
  133. on dlwList:>Delete()
  134. {
  135.  if (dlwList.CurrentIndex != -1)
  136.    {
  137.     declare sName = new String(dlwList.GetString(dlwList.CurrentIndex));
  138.  
  139.     if (sName.SubString(0,2).Text == "+ ")
  140.        {
  141.         sName = sName.SubString(2);
  142.  
  143.         if (IDE.YesNoDialog("Delete Directory: "+dlwList.acCurrentDirectory+sName.Text) == "Yes")
  144.            {
  145.             RemoveDirectory(dlwList.acCurrentDirectory+sName.Text);
  146.             dlwList.FillDirectoryList();
  147.            }
  148.        }
  149.     else if (sName.SubString(0,2).Text == "  ")
  150.        {
  151.         sName = sName.SubString(2);
  152.  
  153.         if (IDE.YesNoDialog("Delete File: "+dlwList.acCurrentDirectory+sName.Text) == "Yes")
  154.            {
  155.             DeleteFile(dlwList.acCurrentDirectory+sName.Text);
  156.             dlwList.FillDirectoryList();
  157.            }
  158.        }
  159.    }
  160. }
  161.  
  162. on dlwList:>Insert()
  163. {
  164.  declare sNewFile = new String(dlwList.GetString(dlwList.CurrentIndex));
  165.  
  166.  if (sNewFile.SubString(1,2).Text == ":\\")
  167.     {
  168.      sNewFile = new String(sNewFile.Text + IDE.SimpleDialog("Create File: "+sNewFile.Text,""));
  169.      if (sNewFile.Length < 4)
  170.         return;
  171.     }
  172.  else
  173.     {
  174.      sNewFile = new String(dlwList.acCurrentDirectory + IDE.SimpleDialog("Create File: " + dlwList.acCurrentDirectory,""));
  175.      if (sNewFile.Length < 1)
  176.         return;
  177.     }
  178.  
  179.  IDE.DoFileOpen(sNewFile.Text);
  180. }
  181.  
  182. on dlwList:>KeyPressed(declare sKeyNames)
  183. {
  184.  if (sKeyNames == "<Ctrl-h>")
  185.    dlwList.PreviousDir();
  186. }
  187.  
  188. on dlwList:>PreviousDir()
  189. {
  190.  declare sDirectory = new String(dlwList.acCurrentDirectory);
  191.  declare nBackslash = sDirectory.Index("\\",SEARCH_BACKWARD);
  192.  if (nBackslash)
  193.     {
  194.      sDirectory = sDirectory.SubString(0,nBackslash-1);
  195.      nBackslash = sDirectory.Index("\\",SEARCH_BACKWARD);
  196.      if (nBackslash)
  197.         {
  198.          dlwList.acCurrentDirectory = sDirectory.SubString(0,nBackslash).Text;
  199.          dlwList.FillDirectoryList();
  200.          return TRUE;
  201.         }
  202.      else
  203.         {
  204.          dlwList.FillDrivesList();
  205.         }
  206.     }
  207. }
  208.  
  209.